package com.copa.task;

import com.copa.utils.MyPrivateMessageUtil;
import com.copa.utils.SimpleCalendarUtil;
import com.copa.utils.TimeUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * @author copa
 * @createDate 2022-03-03 21:43
 * @function
 */
@Component
public class GroupTask {

    @Value("${group.realNum}")
    private String groupNum;

    @Value("${robot.code}")
    private String robotWxid;

    /**
     * 每天23时在群里报晚安~
     */
    @Scheduled(cron = "0 0 23 * * ?")
    public void sleepToGroup() {
        MyPrivateMessageUtil.sendTextMessage(robotWxid, groupNum, "晚安啦~快训啦各位，好夜啦~");
    }


    /**
     * 每天6时在群里报早安~
     */
    @Scheduled(cron = "0 0 6 * * ?")
    public void wakeUpToGroup() {
        MyPrivateMessageUtil.sendTextMessage(robotWxid, groupNum, "早晨，快下床啦各位~");
    }

    /**
     * 每天6时在发送给知乎公众号获取周报~
     */
    @Scheduled(cron = "0 0 6 * * ?")
    public void sendMsgToZhihu() {
        MyPrivateMessageUtil.sendTextMessage(robotWxid, "gh_4132cd5238e8", "图片");
    }

    /**
     * 每天0时在群里报节日快乐吖~
     */
    @Scheduled(cron = "10 0 0 * * ?")
    public void wishToGroup() {
        try {
            DateTimeFormatter dateTimeFormatter = TimeUtil.toTimeFormat("yyyy-MM-dd");
            String lunarFestival = SimpleCalendarUtil.getCalendarDetail(LocalDate.now().format(dateTimeFormatter), "yyyy-MM-dd")
                    .getLunarFestival();
            String solarFestival = SimpleCalendarUtil.getCalendarDetail(LocalDate.now().format(dateTimeFormatter), "yyyy-MM-dd")
                    .getSolarFestival();
            if (!"".equals(lunarFestival)) {
                if ("端午节".equals(lunarFestival)) {
                    MyPrivateMessageUtil.sendTextMessage(robotWxid, groupNum, "今天是" + lunarFestival + "，我祝各位端午安康~");
                    return;
                }
                MyPrivateMessageUtil.sendTextMessage(robotWxid, groupNum, "今天是" + lunarFestival + "，我祝亲们节日快乐吖~(>^ω^<)");
            } else if (!"".equals(solarFestival)){
                MyPrivateMessageUtil.sendTextMessage(robotWxid, groupNum, "今天是" + solarFestival + "，我祝亲们节日快乐吖~(>^ω^<)");
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }


}
